package cn.tedu.dubbo.webapi.service.impl;

import cn.tedu.dubbo.service.CartService;
import cn.tedu.dubbo.webapi.mapper.CartMapper;
import cn.tedu.micro.service.pojo.param.CartAddParam;
import cn.tedu.micro.service.pojo.po.CartPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;


//@Service
@DubboService //该注解标记的类中的方法，会向Nacos中注册
//其他的订阅者(服务的消费者)订阅时会发现当前项目提供的业务逻辑层方法，以备Dubbo调用
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public Boolean addCart(CartAddParam cartAddParam) {
        CartPO cartPO = new CartPO();
        BeanUtils.copyProperties(cartAddParam,cartPO);
        int result = cartMapper.insert(cartPO);
        if(result!=1)
            return false;
        return true;
    }

    @Override
    public Boolean deleteCart(String productCode, String userId) {
        //delete from cart_tbl where product_code=#{productCode} and user_id=#{userId}
        //需要为MP生成的delete  update select 拼接where语句
        //利用QueryWrapper工具实现
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("product_code",productCode);
        queryWrapper.eq("user_id",userId);
        int deleteRows = cartMapper.delete(queryWrapper);
        return deleteRows>=1;
    }

}
